#include <iostream>
#include <vector>

using namespace std;

const int N = 10;
vector<int> path;
int st[N];
int n;

void dfs()
{
	if(path.size() == n)
	{
		for(int i = 0; i < path.size(); i++)
		printf("%5d", path[i]);
		cout << endl;
		return;
	}
	for(int i = 1; i <= n; i ++)
	{
		if(st[i]) continue;
		st[i] = true;
		path.push_back(i);
		dfs();
		st[i] = false;
		path.pop_back();
	}
}

int main()
{
	cin >> n;
	dfs();
	return 0;
}
